# Reference: <https://postmarketos.org/vendorkernel>
# Kernel config based on: arch/arm64/configs/defconfig
# Maintainer: Lux Aliaga <they@mint.lgbt>
pkgname=linux-postmarketos-qcom-sm6125
pkgver=6.1
pkgrel=2
pkgdesc="Mainline Kernel fork for SM6125 devices"
arch="aarch64"
_carch="arm64"
_flavor="postmarketos-qcom-sm6125"
url="https://kernel.org"
license="GPL-2.0-only"
options="!strip !check !tracedeps pmb:cross-native"
makedepends="
	bash
	bc
	bison
	devicepkg-dev
	flex
	openssl-dev
	perl
"

# Source
_repository="linux"
_commit="77de535b8dbd8f483b5802c8937cb714bab5b485"
_config="config-$_flavor.$arch"
source="
	$pkgname-$_commit.tar.gz::https://gitlab.com/sm6125-mainline/$_repository/-/archive/$_commit.tar.gz
	$_config
"
builddir="$srcdir/$_repository-$_commit"


prepare() {
	default_prepare
	cp "$srcdir/config-$_flavor.$arch" .config
}

build() {
	unset LDFLAGS
	# V=1: workaround for pma#1990, remove after upgrading to >= 6.2
	make ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-$_flavor" V=1
}

package() {
	mkdir -p "$pkgdir"/boot

	install -Dm644 "$builddir/arch/$_carch/boot/Image.gz" \
		"$pkgdir/boot/vmlinuz"

	make modules_install dtbs_install \
		ARCH="$_carch" \
		INSTALL_PATH="$pkgdir"/boot/ \
		INSTALL_MOD_PATH="$pkgdir" \
		INSTALL_MOD_STRIP=1 \
		INSTALL_DTBS_PATH="$pkgdir"/boot/dtbs
	rm -f "$pkgdir"/lib/modules/*/build "$pkgdir"/lib/modules/*/source

	install -D "$builddir"/include/config/kernel.release \
		"$pkgdir"/usr/share/kernel/$_flavor/kernel.release
}


sha512sums="
e41aa6fa99cdb76f1748547e1b140721e30ced86d3e2aa2f94cc56be8a8f89fd0578f041061c0b6992cf49e73ee4b78cc6529943d37087c27894094730ca1e93  linux-postmarketos-qcom-sm6125-77de535b8dbd8f483b5802c8937cb714bab5b485.tar.gz
7b7babe738d05cb2bcd84191d8da7c2132643d0cb521a161d5a9356ce661095005bb7968b710777d5a1c1ef1600858daf2a39f07cf7af9b699a88524b51bc324  config-postmarketos-qcom-sm6125.aarch64
"
